﻿
/**
* Masque Dom Library 0.0.2.8
* Copyright(c) 2008, 青岛领创网络科技有限公司
* @author Lookingon Team
*/
if (Masque && !Masque.D) {
    Masque.D = {
        getChildNodes: function(node) {
            var n = $(node);
            if (n == null) {
                return null;
            }
            if (n.childNodes.length == 0) {
                return null;
            }
            var index = -1;

            if (arguments.length > 1) {
                var t = parseInt(arguments[1]);
                if (!isNaN(t)) {
                    index = t;
                }
            }
            if (index > -1) {
                var j = 0;
                for (var i = 0; i < n.childNodes.length; i++) {
                    if (n.childNodes[i].nodeType == 1) {

                        if (j == index) {
                            return n.childNodes[i];
                        }
                        j++;
                    }
                }
            }
            else {
                var nodes = new Array();
                for (var i = 0; i < n.childNodes.length; i++) {
                    if (n.childNodes[i].nodeType == 1) {
                        nodes.push(n.childNodes[i]);
                    }
                }
                return nodes;
            }


        },
        nextSibling: function(node) {
            var n = $(node);
            if (n == null) {
                return null;
            }
            n = n.nextSibling;

            for (n; n != null; n = n.nextSibling) {
                if (n.nodeType == 1)
                    return n;
            }
        },
        prevSibling: function(node) {
            var n = $(node);
            if (n == null) {
                return null;
            }
            n = n.previousSibling;

            for (n; n != null; n = n.previousSibling) {
                if (n.nodeType == 1)
                    return n;
            }
        },
        CancelBubble: function(oEvent) {
            if (oEvent == null)
                oEvent = window.event;
            if (Masque.isIE) { oEvent.cancelBubble = true; } else { oEvent.stopPropagation(); }
        }
    }
}

/*window Extend-------------------------------------------------------*/
window.clientWidth = function() {
    return document.documentElement.clientWidth;
}
window.clientHeight = function() {
    return document.documentElement.clientHeight;
}
window.contentWidth = function() {
    if (Masque.isIE) {
        if (document.body.currentStyle.marginLeft != null) {
            return document.body.offsetWidth + parseInt(document.body.currentStyle.marginLeft) * 2;
        }
        return document.body.offsetWidth;
    }
    else {
        return document.documentElement.offsetWidth;
    }
}
window.contentHeight = function() {
    if (Masque.isIE) {
        if (document.body.currentStyle.marginTop != null) {
            return document.body.offsetHeight + parseInt(document.body.currentStyle.marginTop) * 2;
        }
        return document.body.offsetHeight;
    }
    else {
        return document.documentElement.offsetHeight;
    }
}

/*Element Object-------------------------------------------------------*/
if (!window.Element) {
    Element = {};
}
Element.currentPopup = null;
Element.hide = function() {
    if (arguments.length == 1) {
        $(arguments[0]).style.display = 'none';
    }
    else {
        var nodes = new Array();
        for (var j = 0; j < arguments.length; j++) {
            nodes.push($(arguments[j]));
        }
        for (var i = 0; i < nodes.length; i++) {
            nodes[i].style.display = 'none';
        }
    }
}
Element.show = function() {
    if (arguments.length == 1) {
        if ($(arguments[0]).tagName.toLowerCase() == 'div') {
            $(arguments[0]).style.display = 'block';
        }
        else {
            $(arguments[0]).style.display = '';
        }
    }
    else {
        var nodes = new Array();
        for (var j = 0; j < arguments.length; j++) {
            nodes.push($(arguments[j]));
        }
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].tagName.toLowerCase() == 'div') {
                nodes[i].style.display = 'block';
            }
            else {
                nodes[i].style.display = '';
            }
        }

    }
}
Element.showModal = function(node) {
    Element.hidePopup();
    if (node != null) {
        node = $(node);
        var bcolor = '#383838';
        if (arguments[1] != null) {
            bcolor = arguments[1];
        }
        var backDiv = document.createElement('div');
        document.body.appendChild(backDiv);
        var w = window.clientWidth() < window.contentWidth() ? window.contentWidth() : window.clientWidth();
        var h = window.clientHeight() < window.contentHeight() ? window.contentHeight() : window.clientHeight();
        backDiv.id = 'popupBackDiv';
        //backDiv.style.backgroundColor = bcolor;
        backDiv.style.position = 'absolute';
        backDiv.style.width = w + 'px';
        backDiv.style.height = h + 'px';
        backDiv.style.left = '0px';
        backDiv.style.top = '0px';
        backDiv.style.zIndex = 1;
        if (Masque.isIE) {
            backDiv.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=50,startX=0,startY=0,finishX=100,finishY=100);';
        }
        else {
            backDiv.style.opacity = 0.5;
        }
        Element.show(node);
        node.style.position = 'absolute';
        var left = (window.clientWidth() - node.offsetWidth) / 2 + document.documentElement.scrollLeft;
        var top = (window.clientHeight() - node.offsetHeight) / 2 + document.documentElement.scrollTop;
        if (node.offsetParent != null) {
            var p = GetPosition(node.offsetParent);

            node.style.top = top - p.Top + "px";
            node.style.left = left - p.Left + "px";
        } else {
            node.style.top = top + 'px';
            node.style.left = left + 'px';
        }
        node.style.zIndex = 999;
        Element.currentPopup = node;

        var mendIframe = document.createElement('iframe');
        document.body.appendChild(mendIframe);
        mendIframe.id = "popupMendIframe";
        mendIframe.style.border = "0px";
        mendIframe.style.display = "block";
        mendIframe.style.position = "absolute";
        mendIframe.style.zIndex = 900;
        mendIframe.style.left = left + "px";
        mendIframe.style.top = top + "px";
        if (Masque.isIE) {
            mendIframe.style.height = node.currentStyle.height;
            mendIframe.style.width = node.currentStyle.width;
        }
        else {
            mendIframe.style.height = node.offsetHeight + "px";
            mendIframe.style.width = node.offsetWidth + "px";
        }
        mendIframe.style.margin = "0px";
        mendIframe.style.padding = "0px";
    }
}
Element.hidePopup = function() {
    var node = Element.currentPopup;
    if (arguments[0] != null) {
        node = $(arguments[0]);
    }
    if (node != null) {
        node.style.left = -1000 + 'px';
        node.style.top = -1000 + 'px';
        node.style.position = '';
        Element.hide(node);
    }
    if ($('popupBackDiv') != null) {
        document.body.removeChild($('popupBackDiv'));
    }
    if ($('popupMendIframe') != null) {
        document.body.removeChild($('popupMendIframe'));
    }
}
Element.showModeless = function(node) {
    if (node != null) {
        node = $(node);
        Element.show(node);
        node.style.position = 'absolute';
        if (Number.isNumber(arguments[1]) && Number.isNumber(arguments[2])) {
            node.style.left = arguments[1] + 'px';
            node.style.top = arguments[2] + 'px';
        }
        else {
            node.style.left = (window.clientWidth() - node.offsetWidth) / 2 + document.documentElement.scrollLeft + 'px';
            node.style.top = (window.clientHeight() - node.offsetHeight) / 2 + document.documentElement.scrollTop + 'px';
        }
        node.style.zIndex = 999;
        Element.currentPopup = node;
    }
}
Element.move = function(node, x, y) {
    if (node != null) {
        node = $(node);
        if (node.style.position.toLowerCase() != 'absolute') {
            node.style.position = 'absolute';
        }
        node.style.left = x + 'px';
        node.style.top = y + 'px';
    }
}

Element.moveObj = null;
Element.startDragX = 0;
Element.startDragY = 0;
Element.startDrag = function(node) {
    if (node != null) {
        node = $(node);
        if (node.style.position.toLowerCase() != 'absolute') {
            node.style.position = 'absolute';
            node.style.left = Element.positionLeft(node) + 'px';
            node.style.top = Element.positionTop(node) + 'px';
        }
        if (Masque.isIE) {
            Element.startDragX = window.event.x - parseInt(node.style.left);
            Element.startDragY = window.event.y - parseInt(node.style.top);
        }
        else {
            Element.startDragX = window.event.clientX - parseInt(node.style.left);
            Element.startDragY = window.event.clientY - parseInt(node.style.top);
        }
        Element.moveObj = node;
    }
}
document.onmouseup = function() {
    Element.moveObj = null;
}
//document.onmousemove = function() {
//    if (Element.moveObj != null) {
//        var node = Element.moveObj;
//        if (Masque.isIE) {
//            node.style.left = window.event.x - Element.startDragX + document.body.scrollLeft + 'px';
//            node.style.top = window.event.y - Element.startDragY + document.body.scrollTop + 'px';
//        }
//        else {
//            node.style.left = window.event.clientX - Element.startDragX + 'px';
//            node.style.top = window.event.clientY - Element.startDragY + 'px';
//        }
//    }
//}

Element.popup = {}
Element.popup.display = '';
Element.popup.position = '';
Element.popup.left = '';
Element.popup.top = '';

Element.showTip = function(source, node, px, py) {
    node = $(node);
    source = $(source);
    if (node != null && source != null) {
        Element.popup.display = node.style.diaplay;
        Element.popup.position = node.style.position;
        Element.popup.left = node.style.left;
        Element.popup.top = node.style.top;
        node.style.display = 'block';
        node.style.position = 'absolute';
        if (px == null) {
            px = source.offsetWidth - 0.3 * source.offsetWidth;
        }
        if (py == null) {
            py = source.offsetHeight + 3;
        }
        var posX = Element.positionLeft(source);
        var posY = Element.positionTop(source);
        var w = window.clientWidth() < window.contentWidth() ? window.contentWidth() : window.clientWidth();
        var h = window.clientHeight() < window.contentHeight() ? window.contentHeight() : window.clientHeight();
        if (posX + px + node.offsetWidth > w) {
            node.style.left = posX + 0.7 * source.offsetWidth - node.offsetWidth + 'px';
        }
        else {
            node.style.left = posX + px + 'px';
        }
        if (posY + py + node.offsetHeight > h) {
            node.style.top = posY - 3 - node.offsetHeight + 'px';
        }
        else {
            node.style.top = posY + py + 'px';
        }
        node.style.zIndex = 10;
    }
}

Element.positionLeft = function(node) {
    node = $(node);
    return GetPosition(node).Left;
}
Element.positionTop = function(node) {
    node = $(node);
    return GetPosition(node).Top;
}


function showerrimg(obj, url) {
    var errorimg = "/NoImage/" + url;
    obj.src = errorimg;
    obj.onerror = "";
}